home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 2.iso / dist / fw_html2ps.idb / usr / freeware / lib / html2ps / install.z / install
Text File  |  1999-01-26  |  13KB  |  417 lines

  1. : # Use perl
  2. eval 'exec perl -S $0 "$@"'
  3.   if $running_under_some_shell;
  4.  
  5. $vid=101;
  6. $| = 1;
  7. %p = ("ImageMagick","mogrify", "pbmplus","giftoppm", "netpbm","giftopnm",
  8.       "TeX","tex", "Ghostscript","gs");
  9. @perl = ("Image/Magick.pm", "LWP/UserAgent.pm", "www.pl", "network.pl");
  10. @reqpath = ();
  11.  
  12. die "I am sorry, html2ps requires Perl 5.\n" if($]<5);
  13.  
  14. if(!-e "/dev/null") {
  15.     &getval($goon, "n", "\nThis installation script is for Unix systems, "
  16.     ."and yours does not seem to\nbe one. Do you want to continue anyway?");
  17.     die "\n" if($goon=~/^n/i);
  18. }
  19.  
  20. print <<EOD;
  21.  
  22. This is the installation script for html2ps. To get full functionality, some
  23. external program packages need to be installed. You may wish to install these
  24. first (see the enclosed documentation for addresses):
  25.  
  26.  * For conversion on inline images, any of the packages ImageMagick, pbmplus
  27.    or netpbm.
  28.  
  29.  * To retrieve remote documents you must have either libwww-perl or both the
  30.    Perl files www.pl and network.pl installed. Alternatively, some program
  31.    like url_get or lynx.
  32.  
  33.  * To be able to generate cross references and DSC PostScript, you must
  34.    have Ghostscript installed.
  35.  
  36.  * To be able to convert documents using the MATH element from HTML 3.0,
  37.    you need both TeX and dvips.
  38.  
  39. This script creates a file describing the local configuration. To make this
  40. accurate, you should have your search PATH set to include the directories
  41. where the abovementioned packages are. You must also have write access to
  42. the directories where the files should be placed.
  43. EOD
  44.  
  45. &getval($goon, "y", "\nDo you want to proceed with the installation?");
  46. die "\n" if($goon!~/^y/i);
  47.  
  48. print "\n";
  49. for $req (@perl) {
  50.     print "Searching for $req: ";
  51.     X:for $dir (@INC) {
  52.         if(-f "$dir/$req") {
  53.             $module{$req} = 1;
  54.             print "found ($dir/$req)\n";
  55.             last X;
  56.         }
  57.     }
  58.     print "not found\n" if(!$module{$req});
  59. }
  60.  
  61. $pack = "";
  62. if(&exist("ImageMagick",1)) {
  63.     $pack .= "    ImageMagick: 1;\n";
  64.     $pack .= "    PerlMagick: 1;\n" if($module{"Image/Magick.pm"});
  65. } elsif(&exist("netpbm",1)) {
  66.     $pack .= "    netpbm: 1;\n";
  67. } elsif(&exist("pbmplus",1)) {
  68.     $pack .= "    pbmplus: 1;\n";
  69. }
  70.  
  71. print <<EOW if(!$pack);
  72.  
  73. Could not find any image conversion package (pbmplus, netpbm or ImageMagick)
  74. in your search path. If you want to be able to have inline images (other than
  75. XBM images) included in the PostScript code, you must install one of these
  76. packages. If you do indeed have any of these packages installed, you will
  77. have to edit the configuration file manually, see the documentation for
  78. details.
  79.  
  80. EOW
  81.  
  82. for ("djpeg","TeX","dvips","Ghostscript") {
  83.     if(&exist($_,1)) {
  84.         $pack .= "    $_: 1;\n";
  85.     }
  86. }
  87. if(&exist("weblint",1)) {
  88.     $pack .= "    check: weblint;\n";
  89. }
  90.  
  91. if($module{'LWP/UserAgent.pm'}) {
  92.     $pack .= "    libwww-perl: 1;\n";
  93. } elsif($module{'www.pl'} && $module{'network.pl'}) {
  94.     $pack .= "    jfriedl: 1;\n";
  95. } else {
  96.     if(&exist("lynx",0)) {
  97.         $lynx = 1;
  98.         $lynxcmd = "lynx -source -mime_header";
  99.         $getdef = $lynxcmd;
  100.     }
  101.     if(&exist("url_get",0)) {
  102.         $url_get = 1;
  103.         $ugcmd = "url_get -h";
  104.         $getdef = $ugcmd;
  105.     }
  106.     $both = $url_get && $lynx? "\n(for example '$ugcmd' or '$lynxcmd')": "";
  107.     $none = $url_get || $lynx? "":
  108.            ", or press <return> to convert local files only";
  109.     &getval($geturl, $getdef,
  110.     "\nBy default html2ps uses libwww-perl or the Perl scripts www.pl and "
  111.     ."network.pl to\nretrieve remote documents, I cannot find these on your "
  112.     ."system. You may instead\nuse some command that can retrieve documents "
  113.     ."_with_a_complete_MIME_header_$both\.\nEnter such a command$none");
  114.     $geturl = "/bin/true" if(!$geturl);
  115.     $pack .= "    geturl: \"$geturl\";\n";
  116. }
  117.  
  118. if(@reqpath) {
  119.     $pack .= '    path: "'.join(':',@reqpath).'";';
  120. }
  121.  
  122. chop ($cd = `pwd`);
  123.  
  124. $prefix = "/usr/local";
  125.  
  126. &getval($ans, "y",
  127.  "\nBy default all files will be installed in subdirectories 'bin', 'lib',\n"
  128.  ."and 'man' in a common directory. Is this OK?");
  129. $def = $ans=~/^y/i;
  130.  
  131. if($def) {
  132.     &getval($prefix, "$prefix", "\nEnter the name of this directory");
  133.     &fixdir($prefix);
  134.     &mkdir($prefix,0);
  135. }
  136.  
  137. if($def) {
  138.     $bindir = "$prefix/bin";
  139. } else {
  140.     &getval($bindir, "$prefix/bin",
  141.      "\nEnter the directory where the html2ps script should be put");
  142.     &fixdir($bindir);
  143.     ($prefix) = $bindir=~m|(.*)/[^/]+|;
  144. }
  145. &mkdir($bindir,$def);
  146.  
  147. if($def) {
  148.     $glob = "$prefix/lib/html2ps";
  149. } else {
  150.     &getval($glob, "$prefix/lib/html2ps",
  151.      "\nEnter the the directory where the global configuration file for\n"
  152.     ."html2ps should be put");
  153.     $glob =~ s|/$||g;
  154.     &fixdir($glob);
  155. }
  156. &mkdir($glob,$def);
  157. $repl = "y";
  158. if(-f "$glob/html2psrc") {
  159.     &getval($repl, "y", "\nA file $glob/html2psrc already exists, replace?");
  160. }
  161.  
  162. if($def) {
  163.     $man1 = "$prefix/man/man1";
  164. } else {
  165.     &getval($man1, "$prefix/man/man1",
  166.      "\nEnter the directory for the html2ps manual page");
  167.     &fixdir($man1);
  168. }
  169. &mkdir($man1,$def);
  170.  
  171. if($def) {
  172.     $man5 = "$prefix/man/man5";
  173. } else {
  174.     &getval($man5, "$prefix/man/man5",
  175.      "\nEnter the directory for the manual page describing the configuration\n"
  176.      ."file format for html2ps");
  177.     &fixdir($man5);
  178. }
  179. &mkdir($man5,$def);
  180.  
  181. $ht = "\nTo use the automatic hyphenation feature, hyphenation pattern files\n"
  182.      ."from the TeX distribution are needed.";
  183. $cophy = 1;
  184. if($exist{'TeX'}) {
  185.     $hfile = "";
  186.     ($texdir = $dir{'TeX'}) =~ s|/bin$||;
  187.     SW:for("texmf/tex/generic/hyphen","macros","inputs","lib/macros",
  188.         "lib/inputs","lib/tex/macros","lib/tex/inputs") {
  189.         if(-f "$texdir/$_/ushyph1.tex") {
  190.             $hyph = "$texdir/$_";
  191.             $hfile = "$hyph/ushyph1.tex";
  192.             last SW;
  193.         }
  194.         if(-f "$texdir/$_/hyphen.tex") {
  195.             $hyph = "$texdir/$_";
  196.             $hfile = "$hyph/hyphen.tex";
  197.             last SW;
  198.         }
  199.     }
  200.     if($hfile) {
  201.         &getval($hdef, "y", "$ht I believe that I have found\nthe pattern "
  202.          ."file for English in your TeX installation:\n\n  "
  203.          ."$hfile\n\nWould you like to use this instead of the "
  204.          ."file included with html2ps?");
  205.         if($hdef=~/^y/i) {
  206.             $cophy = 0;
  207.         } else {
  208.             $hfile = "";
  209.         }
  210.     } else {
  211.         &getval($hfile, "", "$ht I cannot find the pattern\nfile for English "
  212.          ."in your TeX installation. (It should be called\n'hyphen.tex', "
  213.          ."or perhaps 'ushyph1.tex', somewhere in the directory\ntree "
  214.          ."'$texdir'.)\n\nIf you know where this file is and want to use it "
  215.          ."instead of the\nfile included with html2ps, enter the full path "
  216.          ."name for this file,\notherwise press <return>");
  217.         while($hfile && !-f $hfile) {
  218.             &getval($hfile, "", "\nNo such file: $hfile\nEnter new name, or "
  219.              ."press <return> to use the supplied file");
  220.         }
  221.         $cophy = $hfile !~ /\S/;
  222.     }
  223.     if(!$hfile) {
  224.         if($def) {
  225.             $hyph = "$prefix/lib/html2ps";
  226.         } else {
  227.             &getval($hyph, "$prefix/lib/html2ps",
  228.              "\nOK, I will use the supplied pattern file for English. Enter "
  229.             ."the directory\nwhere this file should be put");
  230.             &fixdir($hyph);
  231.         }
  232.     }
  233. } else {
  234.     if($def) {
  235.         $hyph = "$prefix/lib/html2ps";
  236.     } else {
  237.     &getval($hyph, "$prefix/lib/html2ps", "$ht A pattern file for English is\n"
  238.      ."included with html2ps (see the documentation how to install pattern\n"
  239.      ."files for other languages). Enter the directory where this file\n"
  240.      ."should be put");
  241.     }
  242. }
  243. if($cophy) {
  244.     &mkdir($hyph,0);
  245.     $hfile = "$hyph/hyphen.tex";
  246. }
  247.  
  248. if($def) {
  249.     $html = "$prefix/lib/html2ps";
  250. } else {
  251.     &getval($html, "$prefix/lib/html2ps",
  252.      "\nEnter a directory where to put the HTML document describing\nhtml2ps");
  253.     &fixdir($html);
  254. }
  255. &mkdir($html,$def);
  256.  
  257. $paper = "";
  258. &getval($format, "A4",
  259.  "\nEnter the default paper type, possible choices are:\nA0, A1, A2, A3, A4,"
  260.  ." A5, A6, A7, A8, A9, A10,\nB0, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10,\n"
  261.  ."letter, legal, arche, archd, archc, archb, archa,\nflsa, flse, halfletter,"
  262.  ." 11x17, ledger, other");
  263. if($format !~ /^other$/i) {
  264.     $paper .= "    type: $format;";
  265. } else {
  266.     &getval($height, "",
  267.      "\nDefault paper height i centimeters (1 inch = 2.54 centimeters)");
  268.     &getval($width, "", "\nDefault paper width i centimeters");
  269.     $paper .= "    height: $height;\n";
  270.     $paper .= "    width: $width;";
  271. }
  272.  
  273. open(RC,">html2psrc") || die "Error openin html2psrc\n";
  274. print RC "/* Global configuration file for html2ps */\n\n"
  275.   ."\@html2ps {\n  package {\n$pack\n  }\n  paper {\n$paper\n  }\n"
  276.   ."  hyphenation {\n    en {\n      file: \"$hfile\";\n    }\n  }\n}\n";
  277. close RC;
  278.  
  279. undef $/;
  280. open(HTML2PS,"html2ps") || die "Error openin html2ps\n";
  281. ($code = <HTML2PS>) =~ s|\$globrc=.*|\$globrc='$glob/html2psrc';|;
  282. close HTML2PS;
  283. open(HTML2PS,">html2ps") || die "Error openin html2ps\n";
  284. print HTML2PS $code;
  285. close HTML2PS;
  286. chmod 0755, "html2ps";
  287.  
  288. $files = "$glob/html2psrc\n.br\n\$HOME/.html2psrc\n.br\n$html/html2ps.html\n";
  289. $files = <<EOF;
  290. .TP
  291. $glob/html2psrc
  292. Global configuration file. See html2psrc(5).
  293. .TP
  294. \$HOME/.html2psrc
  295. User configuration file. See html2psrc(5).
  296. .TP
  297. $html/html2ps.html
  298. Documentation for html2ps.
  299. EOF
  300.  
  301. open(MAN1,"html2ps.1") || die "Error openin html2ps.1\n";
  302. ($code = <MAN1>) =~ s|(\.SH FILES)[\w\W]*(\.SH SEE ALSO)|$1\n$files$2|;
  303. close MAN1;
  304. open(MAN1,">html2ps.1") || die "Error openin html2ps.1\n";
  305. print MAN1 $code;
  306. close MAN1;
  307.  
  308. $odir = "oldfiles.$vid";
  309. $saved = -d $odir;
  310. $backout = "";
  311.  
  312. print "\n";
  313. &inst($bindir,"html2ps");
  314. if(!$saved && -f "$glob/html2psrc") {
  315.     $backout .= "\ncp $odir/html2psrc $glob";
  316.     `cp $glob/html2psrc $odir`;
  317. }
  318. if($repl=~/^y/i) {
  319.     print "Installing html2psrc in $glob\n";
  320.     `cp html2psrc $glob`;
  321. }
  322. &inst($man1,"html2ps.1");
  323. &inst($man5,"html2psrc.5");
  324. if($cophy) {
  325.     print "Installing hyphen.tex in $hyph\n";
  326.     `cp hyphen.tex $hyph`;
  327. }
  328. &inst($html,"html2ps.html");
  329.  
  330. if(!$saved && $backout) {
  331.     open(BACKOUT,">backout") || die "Error openin backout\n";
  332.     print BACKOUT "#!/bin/sh\n$backout\nrm -r $odir\n";
  333.     close BACKOUT;
  334.     chmod 0755, "backout";
  335. }
  336. if(-d $odir) {
  337.     print "\nIf you are not satisfied with this version of html2ps; you can "
  338.          ."execute\nthe script 'backout' to reinstall your earlier version.\n";
  339. }
  340.  
  341. if($repl!~/^y/i) {
  342.     print "\nA new global configuration file 'html2psrc' has been created in "
  343.          ."the current\ndirectory. You can compare this with your old "
  344.          ."configuration file to see if\nany changes need to be done.\n";
  345. }
  346.  
  347. print "\nTesting the installation.\n"
  348.   ."Converting the documentation file 'html2ps.html', using the configuration"
  349.   ."\nfile 'sample'. The output will be written to 'html2ps.ps'.\n";
  350. print `$bindir/html2ps -f sample -o html2ps.ps $html/html2ps.html`;
  351. print $?? "Something went wrong...\n":
  352.           "\nInstallation completed.\nYou may now try to print the file "
  353.          ."'html2ps.ps' in the current directory.\n";
  354.  
  355. sub exist {
  356.     local($package,$flag) = @_;
  357.     $program = $p{$package}? $p{$package}: $package;
  358.     print "Searching for $package: ";
  359.     for $dir (split(/:/,$ENV{'PATH'})) {
  360.         if(-f "$dir/$program") {
  361.             $exist{$package} = 1;
  362.             $dir{$package} = $dir;
  363.             print "found ($dir/$program)\n";
  364.             push(@reqpath,$dir) if(!grep(/^$dir$/,@reqpath) && $flag);
  365.             $dir = $dir;
  366.             return 1;
  367.         }
  368.     }
  369.     print "not found\n";
  370.     0;
  371. }
  372.  
  373. sub mkdir {
  374.     while(!-d $_[0]) {
  375.     $cre = "n";
  376.     while(!-d $_[0] && !$_[1] && $cre!~/^(y|$)/i) {
  377.         &getval($cre, "y", "\nDirectory $_[0] does not exist, create?");
  378.         &getval($_[0], "", "\nEnter new directory name") if($cre!~/^y/i);
  379.         die "Configuration aborted\n" if($_[0] eq "");
  380.     }
  381.      S: while($_[0]=~/\/|$/g) {
  382.         if($` && !-d $`) {
  383.         if(mkdir($`,0755)) {
  384.             print "Created directory $`\n";
  385.         } else {
  386.             print "*** Error creating directory $`: $!\n";
  387.             &getval($_[0], "", "\nEnter new directory name");
  388.             die "Configuration aborted\n" if($_[0] eq "");
  389.             last S;
  390.         }
  391.         }
  392.         }
  393.     }
  394. }
  395.  
  396. sub fixdir {
  397.     $_[0] = "$cd/$_[0]" if($_[0]!~/^\//);
  398.     while($_[0]=~m|[^/]*/\.\./|) {$_[0] = $`.$'};
  399.     $_[0] =~ s|/\./|/|g;
  400. }
  401.  
  402. sub getval {
  403.     $text = $_[1]? "$_[2] [$_[1]]": $_[2];
  404.     print "$text: ";
  405.     ($_[0] = <STDIN>) =~ s/^\s+|[\/\s]+$//g;
  406.     $_[0] = $_[1] if(!$_[0]);
  407. }
  408. sub inst {
  409.     if(!$saved && -f "$_[0]/$_[1]") {
  410.         mkdir($odir,0755) || die "Error creating $odir\n" if(!-d $odir);
  411.         $backout .= "\ncp $odir/$_[1] $_[0]";
  412.         `cp "$_[0]/$_[1]" $odir`;
  413.     }
  414.     print "Installing $_[1] in $_[0]\n";
  415.     `cp $_[1] $_[0]`;
  416. }
  417.